\documentclass[E:/GsjzTle/main/main.tex]{subfiles}
\begin{document}

\begin{itemize}
\item
  \(change(a,b,c,d,x)\)，将\((a,b),(c,d)\)
  为顶点的矩形区域内的所有数字加上 \(x\)
\item
  \(query(a,b,c,d)\)，将\((a,b),(c,d)\)为顶点的矩形区域内所有数字的和
\end{itemize}

\begin{lstlisting}
const int N = 2e3 + 60;
int tree1[N][N], tree2[N][N], tree3[N][N], tree4[N][N];
int lowbit(int x){
	return x & (-x);
}
int n , m;
void update(int x, int y, int d)
{
	for(int i = x; i <= n; i += lowbit(i)) for(int j = y; j <= m; j += lowbit(j))
	{
		tree1[i][j] += d;
		tree2[i][j] += x * d;
		tree3[i][j] += y * d;
		tree4[i][j] += x * y * d;
	}
}
int sum(int x, int y)
{
	int ans = 0;
	for(int i = x; i > 0; i -= lowbit(i)) for(int j = y; j > 0; j -= lowbit(j)) 
	{ 
		ans += (x + 1) * (y + 1) * tree1[i][j] - (y + 1) * tree2[i][j] - (x + 1) * tree3[i][j] + tree4[i][j];
	} 
	return ans;
}
void change(int a , int b , int c , int d , int x)
{
	update(a, b, x) , update(c + 1, d + 1, x);
	update(a, d + 1,-x) , update(c + 1, b, -x);
}
int query(int a , int b , int c , int d)
{
	return sum(c, d)+sum(a-1, b-1)-sum(a-1, d)-sum(c, b-1);
}
signed main()
{
	cin >> n >> m ; 
	char ch[3];
	while(cin >> ch)
	{
		int a , b , c , d , x;
		cin >> a >> b >> c >> d;
		if(ch[0] == 'L')
		{
			cin >> x;
			change(a , b , c , d , x);
		}
		else cout << query(a , b , c , d) << '\n';
	}
	return 0;
}
\end{lstlisting}

\end{document}
